<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import store from '@/store';
export default {
  name: 'App',
  created() {
    if (sessionStorage.getItem('store')) {
      store.replaceState(Object.assign({}, store.state, JSON.parse(sessionStorage.getItem('store'))));
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(store.state));
    });
  },
}
</script>
